package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.MemberMapper;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public Member findByPhone(String telephone) {
        LambdaQueryWrapper<Member> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Member::getPhoneNumber, telephone);
        Member member = memberMapper.selectOne(wrapper);
        return member;
    }

    @Override
    public Member addNewMember(String telephone) {
        Member member = new Member();
        member.setPhoneNumber(telephone);
        member.setRegTime(new Date());
        memberMapper.insert(member);

        LambdaQueryWrapper<Member> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Member::getPhoneNumber, telephone);
        Member member1 = memberMapper.selectOne(wrapper);
        return member1;
    }
}
